const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const basePath = path.resolve(__dirname, '../');

module.exports = {
    entry: './src/index.ts',    //配置启动的入口文件
    devtool: 'cheap-module-eval-source-map',    //不包含列信息，同时 loader 的 sourcemap 也被简化为只包含对应行的
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: 'vue-loader'
            },
            {
                test: /\.tsx?$/, loader: 'ts-loader',
                options: {
                    transpileOnly: true,
                    appendTsSuffixTo: [/.vue$/]
                }
            },
            {
                test: /\.(css|scss)$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', 'sass-loader']
                })
            },
            {
                test: /\.(jpg|jpeg|png|svg)$/i,
                use: 'url-loader?limit=8192&name=images/[name].[ext]'
            }
        ]
    },
    output: {
        filename: 'bundle.js',  //输出的文件名称
        path: path.resolve(basePath, 'dist')   //输出的目录名称
    },
    plugins: [
        new VueLoaderPlugin()
        , new HtmlWebpackPlugin({
            title: '轻生活-生活本该如此撒欢',
            filename: 'index.html',
            template: 'index.html',
            inject: true,
            favicon: path.resolve(basePath, 'favicon.ico'),
            hash: true,
            meta: {
                viewport: 'width=device-width,initial-scale=1.0'
            }
        })
        , new ExtractTextPlugin('style.css')
    ],
    resolve: {
        alias: {
            '@': path.resolve(basePath, 'src'),
            'assets': path.resolve(basePath, 'src/assets')
        }
    }
};